package com.lovo.csc.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.commom.CscRemote.ICscUserOrderRemote;
import com.lovo.csc.bean.UserOrderBean;
import com.lovo.csc.service.IOrderInfoService;
import com.lovo.csc.service.IRefundService;
import com.lovo.csc.service.IUserOrderService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@RestController
@RequestMapping("userOrder")
public class UserOrderController {

    @Autowired
    private IUserOrderService userOrderService;
    @Autowired
    private IRefundService refundService;
    @Autowired
    private ICscUserOrderRemote cscUserOrderRemote;


    //审核通过
    @GetMapping("updateStatus/{userOderId}")
    public String updateStatus(@PathVariable("userOderId") long userOrderId) {
        userOrderService.updateStatus(userOrderId);
        return "ok";
    }

    //审核不通过
    @GetMapping("updateNo/{msg}/{idNum}")
    public String updateNo(@PathVariable("msg") String msg, @PathVariable("idNum") String idNum) {
        refundService.update(msg, idNum);
        return "ok";
    }


    @GetMapping("updateStatus/{orderIdNum}/{status}")
    public String updateStatus(@PathVariable("orderIdNum") String orderIdNum, @PathVariable("status") int status) {
        userOrderService.updateStatus(orderIdNum, status);
        return "ok";
    }

    @GetMapping("findAllNoRefund/{pageNO}")
    public IPage<UserOrderBean> findAllNoRefund(@PathVariable("pageNO") int pageNO) {
        return userOrderService.findAllNoRefund(pageNO);
    }

    @GetMapping("CscUpdateStatus/{orderIdNum}/{status}/{payDate}")
    public boolean CscUpdateStatus(@PathVariable("orderIdNum") String orderIdNum, @PathVariable("status") int status,
                                   @PathVariable("payDate")String payDate) {
        return userOrderService.CscUpdateStatus(orderIdNum, status, LocalDate.parse(payDate));
    }

    @GetMapping("updateStatusTo3/{idNum}")
    public String updateStatusTo3(@PathVariable("idNum") String idNum){
        cscUserOrderRemote.updateStatusTo3(idNum);
        return "ok";
    }

}
